<#include "common/common.html"/>
<meta charset="UTF-8">
<table
	     class="easyui-datagrid"   
	     id="datagrid"  
         title="角色管理"  
         url="${base}/role/list"
         toolbar="#toolbar" 
         rownumbers="true" 
         fitColumns="true"
         singleSelect="true"
         data-options="fit:false,border:false,pageSize:20,pageList:[5,10,15,20]" >  
    <thead>  
        <tr>
            <th field="id" width="5%" checkbox="true"></th>  
            <th field="name" width="45%">角色名</th>
            <th field="remark" width="50%">备注</th>   
        </tr>  
    </thead>  
</table>  
<div id="toolbar">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="javascript:initTree();openNewDlg('角色添加','role/doadd','role-dlg','role-fm');">添加</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="javascript:initTree('edit');openEditDlg('角色修改','role/doupdate','role-dlg','role-fm');">修改</a>
         <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="javascript:singleDel('role/delete');">删除</a>
</div>
<div id="role-dlg" class="easyui-dialog"  style="padding:10px 20px" closed="true" modal="true" buttons="#dlg-buttons">
        <form id="role-fm" method="post">
           <div class="fitem">
                <label>角色名:</label>
                <input id="name" name="name" maxlength="20" class="easyui-textbox" required="true">
           </div>
           <div class="fitem">
                <label>备&nbsp;注:</label>
                <input id="remark" name="remark" maxlength="20" class="easyui-textbox">
           </div>
	       <div class="fitem">
               <label>权&nbsp;&nbsp;限:</label>
               <ul id="privilegeTree" name="privilegeTree" class="easyui-tree"></ul>
               <input type="hidden" id="privilegeStr" name="privilegeStr" maxlength="20">
	        </div>
        </form>
</div>
<div id="dlg-buttons">
    <a href="javascript:void(0)" id="saveBtn" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="javascript:getChecked();submit('role-dlg','role-fm')" style="width:90px">提交</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#role-dlg').dialog('close')" style="width:90px">取消</a>
</div>

<script type="text/javascript">
function formatStatus(val){
	if (val == 1){
		return '可用';
	} else {
		return '不可用';
	}
}

function getChecked(){
	var nodes = $('#privilegeTree').tree('getChecked');
	var s = '';
	for(var i=0; i<nodes.length; i++){
		if (s != '') s += ',';
		s += nodes[i].acl;
	}
	$('#privilegeStr').val(s);
}

function initTree(act){
	var actUrl = '${base}/role/initPrivilege';
	if(act=="edit"){
	   var row = $('#datagrid').datagrid('getSelected');
	   if(row){
		   actUrl+="?id="+row.id;
	   }
	}
	$("#privilegeTree").tree({
		url:actUrl,
		checkbox:'true'
	});
}


</script>
